<?php

class ConfigurationsController extends AppController {
	var $name = 'Configurations';
	var $components = array ('Pagination');
	var $helpers = array('Html','Form','Accessibility','Pagination');

	function index() {
		$title = 'Configurations';
		$this->set('title',$title);
		$this->set('pageTitle',$title);
		
		$configurations = $this->Configuration->find('all');
		$this->set('configurations', $configurations);
	}

	function view( $id=null ) {
		if (!$id) $this->redirect('/configurations');
		
		$title = 'Visualizar configuration';
		$this->set('title',$title);
		$this->set('pageTitle',$title);
		
		$this->Configuration->id = $id;
		$this->set('configuration', $this->Configuration->read());
	}

	function add() {
		$title = 'Cadastrar configuration';
		$this->set('title',$title);
		$this->set('pageTitle',$title);
		
		if (!empty($this->data)) {

			if ($this->Configuration->save($this->data)) { 
				$_SESSION['mensagem']['success'][] = 'Configuration cadastrada com sucesso!';
				$this->redirect('/configurations/view/'.$this->Configuration->getLastInsertId());
			} else {
				$_SESSION['mensagem']['error'][] = 'Erro ao tentar cadastrar a configuration.';
			}
			$this->redirect('/configurations');
		}
	}

	function edit( $id=null) {
		if (!$id) $this->redirect('/configurations');
		$title= 'Editar configuration';
		$this->set('title',$title);
		$this->set('pageTitle',$title);
		
		$this->Configuration->id = $id;
		if (empty($this->data)) {
			$this->data = $this->Configuration->read();
		} else {
			if ($this->Configuration->save($this->data['Configuration'])) {
				$_SESSION['mensagem']['success'][] = 'Configuration alterada com sucesso!';
			} else {
				$_SESSION['mensagem']['error'][] = 'Erro ao tentar alterar a configuration.';
			}
			$this->redirect('/configurations/view/'.$id);
		}
		$configuration = $this->Configuration->find(array('`Configuration`.id' => $id));
		$this->set('configuration', $configuration);
	}

	function delete($id) {
		if (!$id) $this->redirect('/configurations');
		if ($this->Configuration->del($id)) {
			$_SESSION['mensagem']['success'][] = 'Configuration excluida com sucesso!';
		} else {
			$_SESSION['mensagem']['error'][] = 'Erro ao tentar excluir a configuration.';
		}
		$this->redirect('/configurations');
	}
}